package com.ittest.controller;


import com.ittest.config.XMemcachedProperties;
import com.ittest.domain.SMSCode;
import com.ittest.service.SMSCodeService;
import net.rubyeye.xmemcached.exception.MemcachedException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeoutException;

@RestController
@RequestMapping("/sms")
public class SMSCodeController {
    @Autowired
    private XMemcachedProperties memcachedProperties;

    @Autowired
    private SMSCodeService smsCodeService;


    @GetMapping
    public String getCode(String tele) throws InterruptedException, TimeoutException, MemcachedException {
        String code = smsCodeService.sendCodeToSMS(tele);
        System.out.println(memcachedProperties);
        return code;
    }
    @PostMapping
    public boolean checkCode(SMSCode smsCode){
        return smsCodeService.checkcode(smsCode);
    }
}
